<template>
	<view class="myBox">
		<view class="personMsg">
			当前账号：{{account}}
		</view>
		<u-gap height="10" bgColor="#eaebef"></u-gap>
		<u-cell-group>
			<u-cell title="账号安全" @click="goEditPassWord" :isLink="true">
				<u-icon slot="icon" size="40" name="lock"></u-icon>
			</u-cell>
			<u-cell title="注销账户" @click="zxzh = true" :isLink="true">
				<u-icon slot="icon" size="40" name="question-circle"></u-icon>
			</u-cell>
			<u-cell title="系统版本" @click="updataVersion()" :isLink="true">
				<u-icon slot="icon" size="40" name="order"></u-icon>
			</u-cell>
		</u-cell-group>
		<view style="width:90%;margin: 10px auto;text-align: right;font-size: 35upx;">
			<u-link href="https://zhgj.ciciiot.com/privacy.html" style="color: #0062AD;">隐私政策</u-link>
		</view>
		<view class="">
			<view class="loginOut" @click="loginOut()">
				退出账号
			</view>
		</view>
		<u-modal v-model="show" :content="content" :mask-close-able="true"></u-modal>
		<view class="">
			<u-modal :show="version" :show-cancel-button="false" :show-confirm-button="false" title="当前版本"
				:mask-close-able="true">
				<view style="width: 90%;margin: 0 auto;padding: 0 0;">
					<view style="margin-bottom: 20rpx;">
						<text>当前版本：{{versionCon}}</text>
					</view>
					<!-- 	<view style="padding: 5px 0;">
						<text>最新版本：{{newVersion}}</text>
					</view>
					<view class="">
						更新内容：{{info}}
					</view> -->
					<view class="" style="padding: 10px 0;">
						<!-- <u-button
							style="width: 46%;display: inline-block;margin-right:10px;background: #0062AD;color: #fff;"
							type="primary" @click="download">下载
						</u-button>
						<u-button style="width: 46%;display: inline-block;" @click="version = false">
							取消</u-button> -->
						<u-button  type="primary"  @click="version = false">
							确定</u-button>
					</view>
				</view>
			</u-modal>
		</view>
		<u-modal :show="zxzh" showCancelButton title="注销账户"
			content="即将从沥青库管理系统注销您的账户，本操作会删除本机所有内容，以及该账户的所有内容。确定后该账户将不能登录该系统，再次登录需联系管理员。是否确定注销？" confirmColor="#0062AD"
			@confirm="delLoginOut" @cancel="zxzh = false">
		</u-modal>
	</view>
</template>

<script>
	import {
		loginOut,
		delAccount
	} from "../../api/login.js"
	export default {
		data() {
			return {
				show: false,
				content: '',
				form: {
					old_passwd: '',
					new_passwd1: '',
					new_passwd2: ''
				},
				version: false,
				versionCon: '',
				newVersion: '',
				info: '',
				dtask: null,
				zxzh: false,
				account: uni.getStorageSync("account")
			}
		},
		methods: {
			//修改密码
			goEditPassWord() {
				uni.navigateTo({
					url: '/pages/editPassWord/editPassWord'
				});
			},
			//注销账户
			logoOff() {
				logoOff().then(res => {
					if (data.data.result == 1) {
						uni.redirectTo({
							url: '/pages/login/index'
						});
						uni.removeStorageSync('guid');
					}
				})
			},
			download() {
				this.version = false
				this.dtask.start();
				let prg = 0;
				let showLoading = plus.nativeUI.showWaiting(
					"正在下载");
				this.dtask.addEventListener('statechanged', function(
					task, status) {
					// 给下载任务设置一个监听 并根据状态  做操作  
					switch (task.state) {
						case 1:
							showLoading.setTitle("正在下载");
							break;
						case 3:
							prg = parseInt((parseFloat(task
								.downloadedSize
							) / parseFloat(
								task.totalSize
							)) * 100);
							showLoading.setTitle("  正在下载" +
								prg + "%  ");
							break;
						case 4:
							plus.nativeUI.closeWaiting();
							//下载完成  
							break;
					}
				})

			},
			updataVersion() {
				// #ifdef APP-PLUS
				// 获取本地应用资源版本号
				plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
					const version = Number((wgtinfo.version).split('.').join(''));
					this.versionCon = wgtinfo.version;
					this.content = `更是最新版本，当前版本为${this.versionCon}`
					this.version = true
					// getVersion().then(data => {
					// 	if (data.data.result == 1) {
					// 		const newVersion = Number((data.data.data.version).split('.').join(''));
					// 		this.newVersion = data.data.data.version;
					// 		this.info = data.data.data.info;
					// 		if (version !== newVersion) {
					// 			this.version = true;
					// 			this.dtask = plus.downloader.createDownload(data.data.data.down_url, {
					// 				force: true
					// 			}, function(d, status) {
					// 				if (status == 200) { // 下载成功    
					// 					var path = (d.filename);
					// 					plus.runtime.install(path, {}, function() {
					// 						plus.nativeUI.closeWaiting();
					// 						console.log("安装wgt文件成功！");
					// 						plus.nativeUI.alert("应用资源更新完成！", function() {
					// 							plus.runtime.restart();
					// 						});
					// 					}, function(e) {
					// 						plus.nativeUI.closeWaiting();
					// 						console.log("安装wgt文件失败[" + e.code + "]：" + e
					// 							.message);
					// 						plus.nativeUI.alert("安装wgt文件失败[" + e.code +
					// 							"]：" + e.message);
					// 					});
					// 				} else { //下载失败    
					// 					alert("Download failed: " + status);
					// 				}
					// 			});
					// 		} else {
					// 			this.content = `更是最新版本，当前版本为${this.versionCon}`
					// 			this.show = true
					// 		}
					// 	}
					// })
				})
				// #endif
			},
			loginOut() {
				uni.clearStorage();
				uni.redirectTo({
					url: '/pages/login/index'
				});
			},
			delLoginOut() {
				this.zxzh = false;
				delAccount({
					id: uni.getStorageSync("userId")
				}).then(res => {
					if (res.data.code === 1) {
						uni.clearStorage();
						uni.redirectTo({
							url: '/pages/login/index'
						});
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.myBox {
		.personMsg {
			height: 70rpx;
			line-height: 70rpx;
			padding: 20rpx 30rpx;
			font-size: 30rpx;
			color: #303133;
		}

		.loginOut {
			width: 80%;
			height: 85rpx;
			line-height: 85rpx;
			margin: 10% auto;
			text-align: center;
			background: url('../../static/img/btn.png')no-repeat;
			background-size: 100% 100%;
			color: #fff;
			margin-top: 20%;
			font-size: 25upx;
		}

		.u-transition {
			z-index: 110000;
		}

		// 	.pswd {
		// 		position: relative;
		// 		padding: 15px 0;

		// 		.u-input {
		// 			width: 70%;
		// 			position: absolute;
		// 			right: 5%;
		// 			top: 7px;
		// 		}
		// 	}
		// }
	}
</style>
